package cn.ehanghai.iot.utils;

import cn.ehanghai.iot.dataobject.MessageText;
import com.thoughtworks.xstream.XStream;

import java.util.Date;

/**
 * @author xumf
 * @date 2019/6/28 19:25
 */
public class TextMessageUtil {
    public static final String MSGTYPE_EVENT = "event";//消息类型--事件
    public static final String MESSAGE_SUBSCIBE = "subscribe";//消息事件类型--订阅事件
    public static final String MESSAGE_UNSUBSCIBE = "unsubscribe";//消息事件类型--取消订阅事件
    public static final String MESSAGE_TEXT = "text";//消息类型--文本消息
    public static final String MESSAGE_CONTENT= "<a href='http://codexc.natapp4.cc/api?returnUrl=http://codexc.natapp4.cc'>请点击此处</a>前往祝福界面，为祖国留言";

    public static String messageToxml(MessageText message) {
        XStream xstream  = new XStream();
        xstream.alias("xml", message.getClass());
        return xstream.toXML(message);
    }

    public  static  String initMessage(String FromUserName, String ToUserName,String content) {
        MessageText text = new MessageText();
        text.setToUserName(FromUserName);
        text.setFromUserName(ToUserName);
        text.setContent(content);
        text.setCreateTime(new Date().getTime());
        text.setMsgType(MESSAGE_TEXT);
        return  TextMessageUtil.messageToxml(text);
    }

    /*
     * 响应订阅事件--回复文本消息
     */
    public static String subscribeForText(String toUserName,String fromUserName){
        String strLink= "<a href='http://codexc.natapp4.cc/api?returnUrl=http://codexc.natapp4.cc'>请点击此处</a>前往祝福界面，为祖国留言";
        return initMessage(toUserName,fromUserName,strLink);
        //        return initMessage(toUserName, fromUserName,
//                "请点击此处http://codexc.natapp4.cc/api?returnUrl=http://codexc.natapp4.cc，前往祝福界面，为祖国留言");

    }

    /*
     * 响应取消订阅事件
     */
    public static String unsubscribe(String toUserName,String fromUserName){
        //TODO 可以进行取关后的其他后续业务处理
        System.out.println("用户："+ toUserName +"取消关注~");
        return "";
    }



}
